﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.HalfHourCalSave.Common.Basic
{
    public static class SteeringMethods
    {
       /// <summary>
       /// 转向清零
       /// </summary>
       /// <param name="lst"></param>
       /// <param name="zerostandard"></param>
       /// <returns></returns>
        public static List<double>  DoSteeringZero(this List<double> lst,int zerostandard)
        {
            List<double> result = new List<double>();
            for (int i = 0; i < lst.Count; i++)
            {
                if (Math.Abs(lst[i])<=zerostandard)
                {
                    result.Add(0);
                }
                else
                {
                    result.Add(lst[i]);
                }
            }
            return result;
        }

        /// <summary>
        /// 查找并输出转向从0到0的index
        /// </summary>
        /// <param name="lst"></param>
        /// <returns></returns>
        public static List<int> FindSteeringZeroIndex(this List<double> lst)
        {
            List<int> index= new List<int>();
            int start = 0, end;//识别转向开始点数和结束点数
            for (int i = 0; i < lst.Count - 1; i++)
            {
                if (lst[i] == 0 && lst[i + 1] != 0)
                {
                    start = i + 1;
                }
                if (lst[i] != 0 && lst[i + 1] == 0 && start != 0)//这里一定要先找到start才开始找end，否则一开始可能先找到end就不对了
                {
                    end = i;
                    index.Add(start);
                    index.Add(end);
                    start = 0;
                }
            }
            return index;   
        }
    }
}
